//
//  TypeViewController.m
//  GiftNotes
//
//  Created by wsh on 15/8/11.
//  Copyright (c) 2015年 wsh. All rights reserved.
//

#import "TypeViewController.h"
#import "Screen.h"
#import "AttackViewController.h"
#import "GiftViewController.h"
#import "CommonTableViewController.h"
#import "HMSearchBar.h"
#import "UIBarButtonItem+Extension.h"

@interface TypeViewController ()
@property (nonatomic, strong) UISegmentedControl *segment;


@property (nonatomic, strong) AttackViewController *attackVC;
@property (nonatomic, strong) GiftViewController *giftVC;

@end

@implementation TypeViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.barTintColor = [UIColor orangeColor];
    
    _segment = [[UISegmentedControl alloc] initWithItems:@[@"攻略",@"礼物"]];
    
    _segment.bounds = CGRectMake(0, 0, SCREEN_WIDTH / 2.0, 30);
    _segment.selectedSegmentIndex = 0;
    _segment.tintColor = [UIColor whiteColor];
    
    [_segment addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    
    self.navigationItem.titleView = _segment;
    
    [self createDoubleController];
    
    //  改变下一层返回按钮的标题
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
    [self.navigationItem setBackBarButtonItem:backItem];
    
}



#pragma mark --- 创建攻略和礼物对应的controller
- (void)createDoubleController{
    
    _giftVC = [[GiftViewController alloc] init];
    _giftVC.view.frame = CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 49);
    
    //  给子视图传递navigationController属性
    _giftVC.nac = self.navigationController;
    
    
    _attackVC = [[AttackViewController alloc] init];
    _attackVC.view.frame = CGRectMake(0, 64, SCREEN_WIDTH , SCREEN_HEIGHT - 64 - 49);
    _attackVC.nac = self.navigationController;
    
    //  帮自控制器推出下一个界面
    __weak TypeViewController *typeVC = self;
    _attackVC.myBlock = ^(NSString *str ,NSString *nameStr){
        CommonTableViewController *commomVC = [[CommonTableViewController alloc] initWithStyle:UITableViewStylePlain];
        commomVC.urlString = str;
        commomVC.nameString = nameStr;
        commomVC.nac = typeVC.navigationController;
        
        [typeVC.navigationController pushViewController:commomVC animated:YES];
    };
    
    
    [self.view addSubview:_giftVC.view];
    [self.view addSubview:_attackVC.view];
}





#pragma mark --- action
- (void)segmentAction:(UISegmentedControl *)sender{
    
    if (sender.selectedSegmentIndex == 0) {
        [self.view bringSubviewToFront:_attackVC.view];
    } else {
        [self.view bringSubviewToFront:_giftVC.view];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
